import Mock from 'mockjs'
import { MockParams } from './index.model'

const allMockFile: any = import.meta.glob(['./*/!(*.model.ts)'], { eager: true })
const mockList: any = []
for (const key in allMockFile) {
    mockList.push(...allMockFile[key].default)
}

// 设置请求延时
Mock.setup({
    timeout: '200-2000'
})

// 接口拦截
/**
*   params: request url、request methor、request response
*/
export function mockRuqest() {
    mockList.forEach((item: MockParams) => {
        Mock.mock(new RegExp(item.url), item.type || 'get', item.response)
    })
}